<?php
/*
Plugin Name: Blueprint Template System
Plugin URI: http://www.withincode.com/blueprint/wordpress-plugin
Description: Allows Wordpress templates to use the Blueprint template system
Author: Jacob Wright
Version: 0.5
Author URI: http://www.withincode.com
*/

add_filter("404_template", "runBlueprintTemplate");
add_filter("archive_template", "runBlueprintTemplate");
add_filter("author_template", "runBlueprintTemplate");
add_filter("category_template", "runBlueprintTemplate");
add_filter("date_template", "runBlueprintTemplate");
add_filter("home_template", "runBlueprintTemplate");
add_filter("page_template", "runBlueprintTemplate");
add_filter("search_template", "runBlueprintTemplate");
add_filter("single_template", "runBlueprintTemplate");
add_filter("comments_popup_template", "runBlueprintTemplate");


function runBlueprintTemplate($file) {
	global $post, $pages, $pageContents;
	
	// get the template parsed and readied
	require_once(dirname(__FILE__) . "/Blueprint.php");
	$BLUEPRINT_TEMPLATES_DIR = ABSPATH . "wp-content/";
	$BLUEPRINT_CACHE_DIR = ABSPATH . "wp-content/cache/";
	
	
	$file = str_replace($BLUEPRINT_TEMPLATES_DIR, "", $file);
	$layoutFile = preg_replace('|[^/]+$|', "layout.php", $file);
	
	$template = new Blueprint($file);
	$pageContents = $template->fetch();
	$layout = new Blueprint($layoutFile);
	
	return $layout->phpCache;
}


?>